<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<!-- RichFaces tag library declaration -->
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>

<html>
    <head>

        <title>Motorbike tour organizing system | Edit user data</title>
	<style type="text/css">
	.label{
	font-weight:bold;
	}
        </style>

        <style type="text/css">
        <c:import url="styles/decoration.css" />
        </style>

    </head>

    <body>

        <f:view>
	    <f:subview id="headline">
		<c:import url="header.jsp"/>
	    </f:subview>


            <rich:panel header="Edit user data">
		<h:message for="email"/>
                <h:form>
		    <h:outputText value="#{login.error}" style="color:darkred"/>
		    <h:panelGrid columns="2">
                    
			<h:outputText value="Username:"/>
			<h:outputText value="#{editUser.user.name}"/>

			<h:outputText value="E-mail:"/>
			<h:inputText value="#{editUser.email}" required="false" validator="#{editUser.validateEmail}" id="email"/>

			<h:outputText value="Phone number:"/>
			<h:inputText value="#{editUser.phone}" required="false"/>

			<h:commandButton value="Save" action="#{editUser.onSave}"/>
		    </h:panelGrid>
                </h:form>

                <h:form>
		    <h:message for="oldpassword"/>
		    <h:message for="pass1"/>
		    <h:message for="pass2"/>

		    <h:panelGrid columns="2">
			<h:outputText value="Old passsword:"/>
			<h:inputSecret value="#{editUser.oldPassword}" validator="#{editUser.validateOldPassword}" id="oldpassword"/>

			<h:outputText value="New passsword:"/>
			<h:inputSecret value="#{editUser.password}" id="pass1" validator="#{editUser.validateNewPassword}"/>

			<h:outputText value="new passsword again:"/>
			<h:inputSecret value="#{editUser.password2}" id="pass2" validator="#{editUser.validateNewPassword2}"/>

			<h:commandButton value="Change password" action="#{editUser.onChangePassword}"/>
		    </h:panelGrid>
                </h:form>


		<rich:panel>
		    <h:form>
			<h:message for="bike"/>
			<h:panelGrid columns="3">
			    <h:outputText value="Add new bike: " styleClass="label"/>
			    <h:inputText value="#{editUser.bikeType}" required="true" requiredMessage="Please specify the motorbike." id="bike"/>
			    <h:commandButton value="Add" action="#{editUser.onAddBike}"/>
			</h:panelGrid>
		    </h:form>
		</rich:panel>

		<rich:dataTable rowKeyVar="cnt" columns="3" value="#{editUser.user.bikes}" var="bike">
		    <rich:column>
			<f:facet name="header">
			    <h:outputText value="Index"/>
			</f:facet>

			<h:outputText value="#{cnt +1}."/>
		    </rich:column>


		    <rich:column>
			<f:facet name="header">
			    <h:outputText value="Motorbike"/>
			</f:facet>
			<h:outputText value="#{bike.type}"/>
		    </rich:column>

    		    <rich:column>
			<f:facet name="header">
			    <h:outputText value="Action"/>
			</f:facet>
			<h:form>
                            <p>
			    <h:commandButton value="Delete" action="#{editUser.onDeleteBike}">
				<f:setPropertyActionListener value="#{bike.id}" target="#{editUser.bikeId}"/>
			    </h:commandButton>
                            </p>
			</h:form>
		    </rich:column>
		</rich:dataTable>

                <rich:panel header="Interesting trip notification settings">
		    <h:form>
			<h:panelGrid columns="4">
			    From: <rich:calendar value="#{editUser.searchCriteria.startTime}"/>
			    To: <rich:calendar value="#{editUser.searchCriteria.endTime}"/>
			</h:panelGrid>
			<h:panelGrid columns="4">
			    Minimum length: <h:inputText value="#{editUser.searchCriteria.minLength}">
				<f:validateLongRange minimum="0" maximum="50000"/>
			    </h:inputText>

			    Maximum length: <h:inputText value="#{editUser.searchCriteria.maxLength}">
				<f:validateLongRange minimum="0" maximum="50000"/>
			    </h:inputText>
			</h:panelGrid>
                        <h:commandButton value="Notify me!" action="#{editUser.onAddCriteria}"/>
                    </h:form>
                </rich:panel>

		<rich:dataTable rowKeyVar="cnt" columns="6" value="#{editUser.user.searchCriterias}" var="criteria">
		    <rich:column>
			<f:facet name="header">
			    <h:outputText value="Index"/>
			</f:facet>

			<h:outputText value="#{cnt +1}."/>
		    </rich:column>


		    <rich:column>
			<f:facet name="header">
			    <h:outputText value="From"/>
			</f:facet>
			<h:outputText value="#{criteria.startTime}"/>
		    </rich:column>

		    <rich:column>
			<f:facet name="header">
			    <h:outputText value="To"/>
			</f:facet>
			<h:outputText value="#{criteria.endTime}"/>
		    </rich:column>

		    <rich:column>
			<f:facet name="header">
			    <h:outputText value="Minimum Length"/>
			</f:facet>
			<h:outputText value="#{criteria.minLength}"/>
		    </rich:column>

		    <rich:column>
			<f:facet name="header">
			    <h:outputText value="Maximum Length"/>
			</f:facet>
			<h:outputText value="#{criteria.maxLength}"/>
		    </rich:column>

    		    <rich:column>
			<f:facet name="header">
			    <h:outputText value="Action"/>
			</f:facet>
			<h:form>
                            <p>
			    <h:commandButton value="Delete" action="#{editUser.onDeleteCriteria}">
				<f:setPropertyActionListener value="#{criteria.id}" target="#{editUser.criteriaId}"/>
			    </h:commandButton>
                            </p>
			</h:form>
		    </rich:column>
		</rich:dataTable>


            </rich:panel>

        </f:view>
    </body>
</html>

